package eraserhead.entity;

/**
 * Class for a user of a Decision Lines Event
 * @author Quanquan
 * @author Kevin
 */
public class User {
	String name;
	String password;
	boolean isModerator;
	static User userHolder; 
	
	/**
	 * Create a new user for a {@link Decision} event
	 * @param name Username
	 * @param password Password
	 * @param isModerator True if they are the moderator, false otherwise
	 */
	public User(String name, String password, boolean isModerator) {
		this.name = name;
		this.password = password;
		this.isModerator = isModerator;
	}
	
	/**
	 * Statically stores a {@link User}
	 * @param user {@link User} to store	
	 */
	public static void storeUser(User user) {
		userHolder = user;
	}
	
	/**
	 * Gets the statically stores {@link User}
	 * @return Stored {@link User}
	 */
	public static User getUser() {
		return userHolder;
	}
	
	/**
	 * Get the name of the user
	 * @return {@link User}'s name
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Gets the password of the user
	 * @return {@link User}'s password
	 */
	public String getPassword() {
		return password;
	}
	
	/**
	 * Check if the user is a moderator
	 * @return  True if yes; false otherwise
	 */
	public boolean getModeratorStatus() {
		return this.isModerator;
	}
	
	@Override
	public boolean equals(Object other) {
	    if (other == null) {
	    	return false;
	    }
	    if (other == this) {
	    	return true;
	    }
	    if (!(other instanceof User)) {
	    	return false;
	    }
	    User otherUser = (User) other;
	    return otherUser.getName().equals(name);
	}
}
